﻿using Authorization.Center.Controllers;
using Authorization.Center.SqlServer;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using S.ReportForms.Domain.Dto;
using S.ReportForms.Read.API.Application.Command;
using static S.ReportForms.Read.API.Application.Command.BreadMatchingCountCommand;
using static S.ReportForms.Read.API.Application.Command.SheepSoredInRealTimeCommand;

namespace S.ReportForms.Read.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class BreadMatchingCountController : BaseController
    {
        private readonly IMediator mediator;

        public BreadMatchingCountController(MySqlDbContext _db,IMediator mediator) : base(_db)
        {
            this.mediator = mediator;
        }


        /// <summary>
        /// 预估分娩率
        /// </summary>
        /// <returns></returns>
        [Authorize]
        [HttpGet]
        public async Task<EstimatedDeliveryDto> GetBreadMatching(string? breedingDate)
        {
            if (string.IsNullOrEmpty(breedingDate))
            {
                return null ;
            }
            return await mediator.Send(new EstimatedDeliveryCommand() { BreedingDate=breedingDate});
        }


        /// <summary>
        /// 种母分娩率
        /// </summary>
        /// <param name="selectYear">查询的年</param>
        /// <returns></returns>
        [Authorize]
        [HttpGet]
        public async Task<List<BreedingDeliveryRateDto>> GetBreedingDeliveryRate(int? selectYear)
        {
            if(selectYear == null)
            {
                return null;
            }
            return await mediator.Send(new BreedingDeliveryRateCommand()
            {
                SelectYear = (int)selectYear
            });
        }


        /// <summary>
        ///  种母状态分布
        /// </summary>
        /// <param name="varietyId">品种ID</param>
        /// <returns></returns>
        [Authorize]
        [HttpGet]
        public async Task<GetBreedingMothersStateDto> GetBreedingMothersState(int varietyId)
        {
           
            return await mediator.Send(new BreedingMothersStateCommand()
            {
               VarietyId = varietyId
            });
        }
       


    }
}
